/*
 * @lc app=leetcode.cn id=748 lang=cpp
 *
 * [748] 最短补全词
 */

// @lc code=start
class Solution
{
public:
    int isok(int num[], string word)
    {
        for (int i = 0; i < word.size(); i++)
        {
            num[word[i] - 'a']--;
        }
        for (int i = 0; i < 26; i++)
        {
            if (num[i] > 0)
            {
                return 1000; //因为题目所说最大为15
            }
        }
        return word.size();
    }
    string shortestCompletingWord(string licensePlate, vector<string> &words)
    {
        //最短补全词 先遍历licensePlate 有多少字母
        //在查看words中word是否符合要求 并记录符合要求word长度 取最短的那个
        int num[26] = {0}; //初始化一个字符个数数组
        for (int i = 0; i < licensePlate.size(); i++)
        {
            if (islower(licensePlate[i]))
            {
                num[licensePlate[i] - 'a']++;
            }
            else if (isupper(licensePlate[i]))
            {
                num[licensePlate[i] - 'A']++;
            }
        }
        int maxstring = 100;
        string res;
        for (int i = 0; i < words.size(); i++)
        {
            int num2[26] = {0};
            for (int j = 0; j < 26; ++j)
            {
                num2[j] = num[j];
            }
            int tmp = isok(num2, words[i]);
            if (maxstring > tmp)
            {
                maxstring = tmp;
                res = words[i];
            }
        }
        return res;
    }
};
// @lc code=end
